import { ref } from "vue";
import {
  CURDDialogExpose,
  FormItemComponentType,
  FormItemData,
  ModelRules,
  CURDAction,
} from "/@/components/CURDDialog/models";
import { useI18n } from "/@/locales/useI18n";
import { DeviceTypeAiotItem, DeviceTypeItem, ParDeviceTypeItem } from "/@/api/aiot/deviceType/models";
import { ColumnsType } from "ant-design-vue/lib/table";
import { Api, Api_aiot } from "/@/api/aiot/deviceType";
import { ParEquipmentCategoryItem } from "/@/api/aiot/equipmentCategory/models";
import { PatternKey } from "/@/utils/verify";
export function useDeviceType(isPlatform: boolean) {
  const { t } = useI18n();
  //租户窗口实例
  var columns = ref<ColumnsType>([]);
  var model;
  var modelFormSetting: FormItemData[] = [];
  const categoryColumns = ref([
    {
      title: "设备类别名称",
      dataIndex: "equipmentCategoryName",
      width: 200,
    },
    {
      title: "备注",
      dataIndex: "categoryDescription",
      width: 200,
    },
    // {
    //   title: "是否启用",
    //   dataIndex: "isActive",
    //   width: 150,
    // },
  ]);
  if (isPlatform) {
    columns.value = [
      {
        title: t("aiot.deviceType.defaultEquipmentTypeName"),
        dataIndex: "equipmentTypeName",
        width: 200,
      },
      // {
      //   title: t("aiot.deviceType.isActive"),
      //   dataIndex: "isActive",
      //   key: "isActive",
      //   width: 100,
      // },
      {
        title: "备注",
        dataIndex: "descriptions",
        width: 200,
      },
      {
        title: t("common.oper"),
        key: "oper",
        width: 100,
        fixed: "right",
      },
    ];
    model = ref<DeviceTypeAiotItem>({
      equipmentTypeName: "",
      equipmentTypeCode: "",
      equipmentTypePhoto: "",
      descriptions: "",
      // isActive: true,
    });
    modelFormSetting = [
      {
        key: "equipmentTypeName",
        label: t("aiot.deviceType.defaultEquipmentTypeName"),
        max: 32,
        required: true,
      },
      {
        key: "equipmentTypeCode",
        label: t("aiot.deviceType.defaultEquipmentTypeCode"),
        labelDes: "“支持大小写字母、数字和下划线",
        max: 32,
        required: true,
        pattern: PatternKey.code,
      },
      {
        label: t("aiot.deviceType.equipmentTypePhoto"),
        key: "equipmentTypePhoto",
        type: FormItemComponentType.IMGUPLOAD,
      },
      {
        label: "备注",
        max: 200,
        key: "descriptions",
        type: FormItemComponentType.TEXTAREA,
        props: {
          autoSize: { minRows: 3, maxRows: 3 },
        },
      },
      // {
      //   label: t("aiot.deviceType.isActive"),
      //   key: "isActive",
      //   props: {
      //     checkedChildren: "开",
      //     unCheckedChildren: "关",
      //   },
      //   type: FormItemComponentType.SWITCH,
      // },
    ];
  } else {
    columns.value = [
      {
        title: t("aiot.deviceType.defaultEquipmentTypeName"),
        dataIndex: "defaultEquipmentTypeName",
        width: 200,
      },
      // {
      //   title: t("aiot.deviceType.isActive"),
      //   dataIndex: "isActive",
      //   key: "isActive",
      //   width: 100,
      // },
      {
        title: "备注",
        dataIndex: "descriptions",
        width: 200,
      },
      {
        title: t("common.oper"),
        key: "oper",
        width: 100,
        fixed: "right",
      },
    ];
    model = ref<ParDeviceTypeItem>({
      defaultEquipmentTypeName: "",
      defaultEquipmentTypeCode: "",
      defaultEquipmentTypePhoto: "",
      descriptions: "",
      // isActive: true,
    });
    modelFormSetting = [
      {
        key: "defaultEquipmentTypeName",
        label: t("aiot.deviceType.defaultEquipmentTypeName"),
        max: 32,
        required: true,
      },
      // {
      //   label: t("aiot.deviceType.isActive"),
      //   key: "isActive",
      //   type: FormItemComponentType.SWITCH,
      // },
      {
        key: "defaultEquipmentTypeCode",
        label: t("aiot.deviceType.defaultEquipmentTypeCode"),
        labelDes: "“支持大小写字母、数字和下划线",
        max: 32,
        required: true,
        pattern: PatternKey.code,
      },
      {
        label: t("aiot.deviceType.equipmentTypePhoto"),
        key: "defaultEquipmentTypePhoto",
        type: FormItemComponentType.IMGUPLOAD,
      },
      {
        label: "备注",
        key: "descriptions",
        type: FormItemComponentType.TEXTAREA,
        max: 200,
        props: {
          autoSize: { minRows: 3, maxRows: 3 },
        },
      },
    ];
  }

  // 设备类别
  const cateGoryModelFormSetting: FormItemData[] = [
    {
      key: "equipmentCategoryName",
      label: "设备类别名称",
      max: 32,
      required: true,
      // pattern: PatternKey.name,
    },
    {
      key: "categoryDescription",
      label: "备注",
      max: 200,
      // pattern: PatternKey.name,
    },
    // {
    //   key: "isActive",
    //   label: "是否启用",
    //   type: FormItemComponentType.SWITCH,
    //   // pattern: PatternKey.name,
    // },
    {
      key: "equipmentCategoryId",
      hide: true,
    },
  ];
  const cateGoryModel = ref<ParEquipmentCategoryItem>({
    equipmentCategoryName: "",
    categoryDescription: "",
    // isActive: true,
  });
  return {
    Api: isPlatform ? Api_aiot : Api,
    model,
    modelFormSetting,
    columns,
    categoryColumns,
    cateGoryModelFormSetting,
    cateGoryModel,
  };
}
